$(document).ready(function() {

	var right = $("#RightID").text();
	if(right=="ok"){
//		alert(right);
		//alert("adive");
		$(".getbackButton").hide();
		$("#Time").show();
		$("#Person").show();
		$("#MYadiveID").show();
		$(".MYButtonID").show();
	}
	else if(right=="has_no_right"){
//		alert(right);
		$("#Time").hide();
		$("#Person").hide();
		$(".getbackButton").show();
		$("#MYadvieID").hide();
		$(".MYButtonID").hide();
	}else if(right=="read_task_over_request"){
//		alert(right);
		$("#Time").hide();
		$("#Person").hide();
		$(".getbackButton").hide();
		$("#MYadvieID").hide();
		$(".MYButtonID").hide();
	}
	
	function getParams(){       //收集请求参数
		var toid=$.trim($("#toid").val());
		var tId=$.trim($("#tId").val());
		var tTime=$.trim($("#tTime").val());
		var reason=$.trim($("#reason").val());
		var advice=$.trim($("#advice").val());        //处置建议或退办理由
		var applyPerson = $.trim($("#applyPerson").val());   //办结申请人
		var tPerson=$.trim($("#tPerson").val());    //办结人
		params = {
				"queryOption['toid']":toid,
				"queryOption['taskid']":tId,
		 		"queryOption['toTime']":tTime,
				"queryOption['toReason']":reason,	
				"queryOption['advice']":advice,	
				"queryOption['tPerson']":tPerson,	
				"queryOption['applyPerson']":applyPerson,	
				};
		return params;
	}
	
	function agreeAjax(d){
		$.ajax({
			type : "post",
			url: "lzw/TaskOver_over.action",
			data : d,
			success : function(data){
			alert(data.message);
		}
       });
	}
	
	function disagreeAjax(d){
		$.ajax({
			type : "post",
			url: "lzw/TaskOver_disagree.action",
			data : d,
			success : function(data){
			alert(data.message);
		}
       });
	}
		
	function getBackAjax(d){
		$.ajax({
			type : "post",
			url: "lzw/TaskOver_getBack.action",
			data : d,
			success : function(data){
			alert(data.message);
		}
       });
	}
	
	//办结
	$("#agree").click(function(){
		var tTime=$.trim($("#tTime").val());
		var advice=$.trim($("#advice").val());
		var tPerson=$.trim($("#tPerson").val());
		if(tTime==""||advice==""||tPerson==""){
			  alert("请认真填写办结表各项内容！");
			  return;
		  }
		if(!confirm("确定要办结吗？"))
		{
			return;
		}
		else{
		    agreeAjax(getParams());
		    t = "window.location.href='/ag/lzw/task_over_request_list.jsp'";
		    window.setTimeout(t,2000);
		  }
	});
	
	//退办
	$("#disagree").click(function(){
		var tTime=$.trim($("#tTime").val());
		var advice=$.trim($("#advice").val());
		var tPerson=$.trim($("#tPerson").val());
		if(tTime==""||advice==""||tPerson==""){
			  alert("请认真填写办结表各项内容！");
			  return;
		  }
		if(!confirm("确定要退办吗？"))
		{
			return;
		}else{
		    disagreeAjax(getParams());
		    t = "window.location.href='/ag/lzw/task_over_request_list.jsp'";
		    window.setTimeout(t,2000); 
		  }
		});
	
	//返回
	$("#return").click(function(){
		 window.location.href="/ag/lzw/task_over_request_list.jsp";       
		});
	
	//收回申请
	$("#getback").click(function(){		
		if(!confirm("确定要收回申请吗？"))
		{
			return;
		}else{
		    getBackAjax(getParams());
		    t = "window.location.href='/ag/lzw/task_over_request_list.jsp'";
		    window.setTimeout(t,2000); 
		  }
		});
});	

